home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 November / PCWorld_2006-11_cd.bin / system / innosetup / isetup-5.1.8.exe / {app} / Examples / CodeExample1.iss (.txt) < prev    next >
Encoding:
Inno Setup Script  |  2006-10-03  |  4.6 KB  |  95 lines

  1. ; -- CodeExample1.iss --
  2. ; This script shows various things you can achieve using a [Code] section
  3. [Setup]
  4. AppName=My Program
  5. AppVerName=My Program version 1.5
  6. DefaultDirName={code:MyConst}\My Program
  7. DefaultGroupName=My Program
  8. UninstallDisplayIcon={app}\MyProg.exe
  9. InfoBeforeFile=Readme.txt
  10. OutputDir=userdocs:Inno Setup Examples Output
  11. [Files]
  12. Source: "MyProg.exe"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.exe'); AfterInstall: AfterMyProgInstall('MyProg.exe')
  13. Source: "MyProg.chm"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.chm'); AfterInstall: AfterMyProgInstall('MyProg.chm')
  14. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  15. [Icons]
  16. Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
  17. [Code]
  18.   MyProgChecked: Boolean;
  19.   MyProgCheckResult: Boolean;
  20.   FinishedInstall: Boolean;
  21. function InitializeSetup(): Boolean;
  22. begin
  23.   Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
  24.   if Result = False then
  25.     MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  26. procedure DeinitializeSetup();
  27.   FileName: String;
  28.   ResultCode: Integer;
  29. begin
  30.   if FinishedInstall then begin
  31.     if MsgBox('DeinitializeSetup:' #13#13 'The [Code] scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
  32.       FileName := ExpandConstant('{uninstallexe}');
  33.       if not Exec(FileName, '', '', SW_SHOWNORMAL, ewNoWait, ResultCode) then
  34.         MsgBox('DeinitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
  35.     end else
  36.       MsgBox('DeinitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  37.   end;
  38. procedure CurStepChanged(CurStep: TSetupStep);
  39. begin
  40.   if CurStep = ssPostInstall then
  41.     FinishedInstall := True;
  42. function NextButtonClick(CurPageID: Integer): Boolean;
  43.   ResultCode: Integer;
  44. begin
  45.   case CurPageID of
  46.     wpSelectDir:
  47.       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
  48.     wpSelectProgramGroup:
  49.       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
  50.     wpReady:
  51.       begin
  52.         if MsgBox('NextButtonClick:' #13#13 'Using the script, files can now be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
  53.           ExtractTemporaryFile('myprog.exe');
  54.           if not Exec(ExpandConstant('{tmp}\myprog.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
  55.             MsgBox('NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
  56.         end;
  57.         BringToFrontAndRestore();
  58.         MsgBox('NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
  59.       end;
  60.   end;
  61.   Result := True;
  62. function ShouldSkipPage(PageID: Integer): Boolean;
  63. begin
  64.   { Skip wpInfoBefore page; show all others }
  65.   case PageID of
  66.     wpInfoBefore:
  67.       Result := True;
  68.   else
  69.     Result := False;
  70.   end;
  71. procedure CurPageChanged(CurPageID: Integer);
  72. begin
  73.   case CurPageID of
  74.     wpWelcome:
  75.       MsgBox('CurPageChanged:' #13#13 'Welcome to the [Code] scripting demo. This demo will show you some possibilities of the scripting support.' #13#13 'The scripting engine used is RemObjects Pascal Script by Carlo Kok. See http://www.remobjects.com/?ps for more information.', mbInformation, MB_OK);
  76.     wpFinished:
  77.       MsgBox('CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
  78.   end;
  79. function MyProgCheck(): Boolean;
  80. begin
  81.   if not MyProgChecked then begin
  82.     MyProgCheckResult := MsgBox('MyProg:' #13#13 'Do you want to install MyProg.exe and MyProg.chm to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
  83.     MyProgChecked := True;
  84.   end;
  85.   Result := MyProgCheckResult;
  86. procedure BeforeMyProgInstall(S: String);
  87. begin
  88.   MsgBox('BeforeMyProgInstall:' #13#13 'Setup is now going to install ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
  89. procedure AfterMyProgInstall(S: String);
  90. begin
  91.   MsgBox('AfterMyProgInstall:' #13#13 'Setup just installed ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
  92. function MyConst(Param: String): String;
  93. begin
  94.   Result := ExpandConstant('{pf}');
  95.